package com.gticket.customerbackend.handler;

import com.gticket.customerbackend.pojo.Orders;
import com.gticket.customerbackend.pojo.ResponseDate;
import com.gticket.customerbackend.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Data
@Api(tags = "订单展示")
@RequestMapping("/orders")
public class OrderHandler {
    @Autowired
    private OrderService orderService;

    @ApiOperation(value = "查询所有orders",notes = "")
//    @Cacheable(value = "listLevels",keyGenerator = "myKeyGenerator")
    @GetMapping
    public ResponseDate listOrders(Orders order){
        ResponseDate responseDate=new ResponseDate();
        try {
            List<Orders> orders=orderService.listOrders(order);
//            for(int i=0;i<orders.size();i++){
//
//            }
            System.out.println(orders);
            responseDate.setCode(200);
            responseDate.setMsg("查询成功");
            responseDate.setData(orders);
        }catch (Exception e){
            responseDate.setCode(500);
            responseDate.setMsg("接口异常");
        }
        return responseDate;
    }

    @ApiOperation(value = "查询所有orders通过状态",notes = "")
//    @Cacheable(value = "listLevels",keyGenerator = "myKeyGenerator")
    @GetMapping("/state")
    public ResponseDate listOrdersByState(Orders order){
        ResponseDate responseDate=new ResponseDate();
        try {
            List<Orders> orders=orderService.listOrdersByState(order);
            responseDate.setCode(200);
            responseDate.setMsg("查询成功");
            responseDate.setData(orders);
        }catch (Exception e){
            responseDate.setCode(500);
            responseDate.setMsg("接口异常");
        }
        return responseDate;
    }
}


